package com.lmk.homework;

import java.util.Scanner;

public class work08 {
    public static void main(String[] args) {
        System.out.println("质数");
        int count = 0;
        for (int i = 11; i <= 105; i = i + 2) {  //偶数不可能为素数
            boolean a = true;
            for (int j = 3; j < i; j++) {
                if (i % j == 0) {          //只要存在一个因子就不是素数
                    a = false;
                    break;
                }
            }
            if (a == true) {
                System.out.print(i+"  ");
                count = count + 1;
            }
        }
        System.out.println("             ");
        int start=10;
        int end=105;
        for (int i = start; i <= end; i++) {
            boolean ok=true;
            for (int j = 2; j <=(int)Math.sqrt(i) ; j++) {

                if(i%j==0){
                   ok=false;
                   break;
                }
            }  if (ok){
                System.out.print(i+"  ");
            }
        }

        System.out.println("****************************************************************************************");
        System.out.println("水仙数");
        for (int x = 100; x < 1000; x++) {
            //获取个位，十位，百位
            int ge = x % 10;
            int shi = x / 10 % 10;
            int bai = x / 10 / 10 % 10;

            //让每个位上的立方和相加，并和该数据进行比较，如果相等，就说明该数据是水仙花数，在控制台输出
            if ((ge * ge * ge + shi * shi * shi + bai * bai * bai) == x) {
                System.out.print(x+" ");
            }

        }
        int q=100; int e=500;
        int g = 0;
        int sh = 0;
        int b = 0;
        for (int i = q; i <=e; i++) {
             g = i % 10;
             sh = i / 10 % 10;
             b = i / 10 / 10 % 10;
             if(g*g*g+sh*sh*sh+b*b*b==i){
                 System.out.print(i+"  ");
             }
        }


        System.out.println("****************************************************************************************");
        System.out.println("完整数");
        for (int m = 1; m <= 100; m++)//从1开始取值
        {
            int s = 0;//定义整型S
            for (int i = 1; i < m; i++)//
                if (m % i == 0)  //如果M除以i整除
                    s = s + i;
            if (s == m) { //如果S=M
                System.out.print(s + " "); //输出完数
            }
        }
        for (int i = 1; i <=100 ; i++) {
            int sun=0;
            for (int j = 1; j <i; j++) {
                if(i%j==0){
                    sun+=j;
                }
            }if(sun==i){
                System.out.print(i + " ");
            }

        }
        System.out.println("****************************************************************************************");
        System.out.println("逆顺序输出");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数");
        int x = sc.nextInt();
        int y = 0, z;
        int i = 0, a = 0;
        boolean flag = false;
        //判断是否为负数
        if (x < 0) {
            x = Math.abs(x);
            flag = true;
        }
        //计算位数以及整理倒叙
        while (x > 0) {
            z = x % 10;
            y = y * 10 + z;
            x /= 10;
            i++;
        }
        //根据整数或者负数倒序输出
        if (flag) {
            System.out.println("这个整数是" + i + "位数。");
            System.out.println("逆序输出：-" + y);
        } else {
            System.out.println("这个整数是" + i + "位数。");
            System.out.println("逆序输出：" + y);
        }
        System.out.println("****************************************************************************************");
        System.out.println("以下为2000年~3000年中的闰年");
        int year;
        for(year=2000;year<=3001;year++){
            if((year%400==0)||(year%4==0&&year%100!=0)){
                System.out.print(year + " ");
            }
        }

    }
}